package com.aj.service;
import com.aj.Interface.PermissionService;
import com.aj.dao.PermissionDao;
import com.aj.pojo.Permission;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service(interfaceClass =PermissionService.class )
@Transactional
public class PermissionServiceImpl implements PermissionService {


    @Autowired
    private PermissionDao permissionDao;

    @Override
    public List<Permission> findall() {
        List<Permission>  checkItems = permissionDao.findall();
        return checkItems;
    }

    @Override
    public void update(Permission permission) {
        permissionDao.update(permission);
    }
 @Override
    public List<Permission> findAll() {
        return permissionDao.findAll();
    }
    @Override
    public Permission findbyid(Integer id) {
        return permissionDao.findbyid(id);
    }

    @Override
    public void add(Permission permission) {
        permissionDao.add(permission);
    }

    @Override
    public PageResult findPage(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage, pageSize);
        Page<Permission> Page=  permissionDao.findPage(queryString);
        return new PageResult(Page.getTotal(),Page.getResult());
    }

    @Override
    public void delete(Integer id) {
        //这边权限是和role角色表关联的 需要先查询t_role_permission表中有没有关联项
        long findgrounp = permissionDao.findrole(id);
        if (findgrounp>0){
            throw new RuntimeException("该权限被引用,无法删除");
        }else {
            permissionDao.delete(id);
        }
    }
}
